// stdx/strx.rs
// CRITICAL: &str 与 String 的常见方法（trim, split, to_lowercase, replace）。

#[allow(dead_code)]
pub fn stdx_examples_strx() {
    let s: &str = " Hello Rust ";
    let t = s.trim();
    let lower = t.to_lowercase();
    let parts: Vec<&str> = t.split_whitespace().collect();
    let replaced = t.replace("Rust", "stdx");
    let _ = (t, lower, parts, replaced);

    // CRITICAL: 字符串长度和字节
    let len_chars = s.chars().count();
    let len_bytes = s.len();

    // CRITICAL: 子串检查
    let contains_rust = s.contains("Rust");
    let starts_with_space = s.starts_with(' ');
    let ends_with_space = s.ends_with(' ');

    // CRITICAL: 字符串分割
    let split_lines: Vec<&str> = "line1\nline2\nline3".lines().collect();
    let split_comma: Vec<&str> = "a,b,c".split(',').collect();

    // CRITICAL: 字符串查找
    let find_rust = s.find("Rust");
    let rfind_space = s.rfind(' ');

    // CRITICAL: 字符串切片
    let slice = &s[1..6]; // "Hello"

    // CRITICAL: 字符串转换
    let upper = s.to_uppercase();
    let ascii_upper = s.to_ascii_uppercase();

    // CRITICAL: 字符串重复
    let repeated = "ha".repeat(3);

    // CRITICAL: 字符串解析
    let parsed_int: Result<i32, _> = "42".parse();
    let parsed_float: Result<f64, _> = "3.14".parse();

    // CRITICAL: 字符串与字节转换
    let bytes = s.as_bytes();
    let from_utf8: Result<&str, _> = std::str::from_utf8(bytes);

    let _ = (
        len_chars,
        len_bytes,
        contains_rust,
        starts_with_space,
        ends_with_space,
        split_lines,
        split_comma,
        find_rust,
        rfind_space,
        slice,
        upper,
        ascii_upper,
        repeated,
        parsed_int,
        parsed_float,
        bytes,
        from_utf8,
    );
}
